package com.cskaoyan.day14;

public class Lambda {
    public static void main(String[] args) {
        INoReturnNoParam iNoReturnNoParam = () -> {
            System.out.println("无返回值无参数的功能接口");
        };
        iNoReturnNoParam.test();

        INoReturnOneParam iNoReturnOneParam = (a) -> {
            System.out.println("无返回值有一个参数的功能接口,参数是" + a);
        };
        iNoReturnOneParam.test(1);

        INoReturnTwoParam iNoReturnTwoParam = new Lambda()::testMethod;
        iNoReturnTwoParam.test(2, 3);

        System.out.println("有返回值无参数的功能接口：返回值是:" + TestNoParam().test());

        IHasReturnOneParam iHasReturnOneParam = (a) -> {
            return a;
        };
        System.out.println("iHasReturnOneParam.method(1) = " + iHasReturnOneParam.method(1));

        IHasReturnTwoParam iHasReturnTwoParam = Lambda::add;
        System.out.println("iHasReturnTwoParam.Constructor(1,2) = " + iHasReturnTwoParam.test(1, 2));
    }

    static int add(int a, int b) {
        return a + b;
    }

    void testMethod(int a, int b) {
        System.out.println("无返回值两个参数的功能接口,参数是: " + a + "  ," + b);
    }

    public static IHasReturnNoParam TestNoParam() {
        return () -> {
            return 1;
        };
    }
}

//无返回值无参数的功能接口
@FunctionalInterface
interface INoReturnNoParam {
    void test();
}

//无返回值有一个参数的功能接口
@FunctionalInterface
interface INoReturnOneParam {
    void test(int a);
}

//无返回值两个参数的功能接口
@FunctionalInterface
interface INoReturnTwoParam {
    void test(int a, int b);
}

//有返回值无参数的功能接口
@FunctionalInterface
interface IHasReturnNoParam {
    int test();
}

//有返回值一个参数的功能接口
@FunctionalInterface
interface IHasReturnOneParam {
    int method(int a);
}

//有返回值两个参数的功能接口
@FunctionalInterface
interface IHasReturnTwoParam {
    int test(int a, int b);
}